﻿/*
 * MIT License
 *Copyright (c) 2021 咖啡与网络(java-and-net)
 *
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using CoreShop.Library;
using CoreShop.Model;
using CoreShop.Repository;
using Newtonsoft.Json;
using SqlSugar;

namespace CoreShop.Services
{
    /// <summary>
    /// 接口实现类
    /// </summary>
    public class corecmssystemsetupService : Repository<corecmssystemsetup>, IcorecmssystemsetupService
    {
        #region 支付信息
                

        /// <summary>
        /// 更新商品分类 删除标志
        /// </summary>
        /// <param name="custo"></param>
        /// <returns></returns>
        public bool UpdDataInfo(corecmssystemsetup systemsetup)
        {
            var bl = base.Update(a => new corecmssystemsetup()
            {
                orderNumberType = systemsetup.orderNumberType,
            }, a => a.storeId == systemsetup.storeId);
            return bl;
        }
    

        /// <summary>
        /// 查询所有商品分类信息
        /// </summary>
        /// <returns></returns>
        public List<corecmssystemsetup> SelectDataAll()
        {
            //查询出所有商品分类信息
            List<corecmssystemsetup> systemsetups = new List<corecmssystemsetup>();
            var where = Expressionable.Create<corecmssystemsetup>();
            where = where.And(a => a.storeId > 0);
            systemsetups = base.AsQueryable().WhereIF(true, where.ToExpression())
                    .OrderBy(a => a.storeId).ToList();

            return systemsetups;
        }
                

        /// <summary>
        /// 
        /// </summary>
        /// <param name="CustoNo"></param>
        /// <returns></returns>
        public corecmssystemsetup SelectDataFirst()
        {
            var systemsetups = base.GetFirst(p=>p.id > 0);
            if ((systemsetups != null) && (CommFunc.ConvertNullString(systemsetups.paraPartial) != ""))
            {
                ParaPartialModel paraPartialModel = JsonConvert.DeserializeObject<ParaPartialModel>(systemsetups.paraPartial);
                systemsetups.paraPartialModel = paraPartialModel;
            }
            if (systemsetups.starWeight == 0) systemsetups.starWeight = 5;//不能为0
            return systemsetups;
        }
        #endregion
    }
}
